package com.bienvenue.main.ui.fragment.personal;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;

import com.bienvenue.main.R;
import com.bienvenue.main.adapter.MainPositionsAdapter;
import com.bienvenue.main.base.BaseFragment;
import com.bienvenue.main.model.MainBean;

import com.bienvenue.main.ui.activity.personal.HotJobActivity;
import com.bienvenue.main.ui.activity.personal.HotPromptActivity;
import com.bienvenue.main.ui.activity.personal.JobSearchActivity;
import com.bienvenue.main.ui.activity.personal.PositionDetailsActivity;
import com.bienvenue.main.ui.activity.personal.PositionsTypeActivity;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @ProjectName: Bienvenue
 * @Package: com.bienvenue.main.ui.fragment
 * @ClassName: BienvenueFragment
 * @Description: 招聘Fragment
 * @Author: Mr.Chen
 * @CreateDate: 2020/9/7 11:07
 * @UpdateUser: Mr.Chen
 * @UpdateDate: 2020/9/7 11:07
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */


public class MainFragment extends BaseFragment implements OnBannerListener {
    MainPositionsAdapter mAdapter;

    @BindView(R.id.rv_position_list)
    RecyclerView rvPositionList;
    @BindView(R.id.banner)
    Banner banner;

    @Override
    protected void initData() {
        rvPositionList.setLayoutManager(new LinearLayoutManager(getContext()));
        mAdapter = new MainPositionsAdapter();
        rvPositionList.setAdapter(mAdapter);

        List<MainBean> mainList = new ArrayList<>();
        MainBean mainBean = new MainBean();
        mainBean.setAddress("陕西 西安 未央");
        mainBean.setEducation("3~5年大专");
        mainBean.setMoneyIntervalle("￥16~20K");
        mainBean.setPositionsType("软件开发");
        mainBean.setPromptName("西安陇朝盈科技责任有限公司");
        mainList.add(mainBean);
        mAdapter.setNewData(mainList);
        mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
             Intent intent=new Intent(getActivity(), PositionDetailsActivity.class);
             startActivity(intent);
            }
        });

    }

    @Override
    protected void initView(View view) {
        List<Integer> imgList = new ArrayList<>();
        imgList.add(R.mipmap.icon_banner);
        imgList.add(R.mipmap.icon_banner);
        imgList.add(R.mipmap.icon_banner);
        List<String> titles = new ArrayList<>();
        titles.add("迎聘招聘1");
        titles.add("迎聘招聘2");
        titles.add("迎聘招聘3");


        banner.setOnBannerListener(this);
        //设置banner样式
        banner.setBannerStyle(BannerConfig.NOT_INDICATOR);
        //设置图片加载器
        banner.setImageLoader(new MyLoader());
        //设置图片集合
        banner.setImages(imgList);
        //设置banner动画效果
        banner.setBannerAnimation(Transformer.Default);
        //设置标题集合（当banner样式有显示title时）
        banner.setBannerTitles(titles);
        //设置自动轮播，默认为true
        banner.isAutoPlay(true);
        //设置轮播时间
        banner.setDelayTime(1500);
        //设置指示器位置（当banner模式中有指示器时）
        banner.setIndicatorGravity(BannerConfig.CENTER);
        //banner设置方法全部调用完毕时最后调用
        banner.start();

    }
    @Override
    public void OnBannerClick(int position) {
     showToast("此功能暂未实现");
    }
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_main;
    }

    //如果你需要考虑更好的体验，可以这么操作
    @Override
    public void onStart() {
        super.onStart();
        //开始轮播
        banner.startAutoPlay();
    }

    @Override
    public void onStop() {
        super.onStop();
        //结束轮播
        banner.stopAutoPlay();
    }

    private class MyLoader extends ImageLoader {//inner Class

        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Glide.with(getContext()).load(path).into(imageView);
        }
    }

    @OnClick(R.id.tv_city_code)
    void OnCityCodeClick() {
        showToast("此功能暂未实现");
    }

    @OnClick(R.id.tv_positions_type)
    void OnPositionType() {
        //跳转到只为类型
        Intent intent=new Intent(getActivity(), PositionsTypeActivity.class);
        startActivity(intent);

    }

    @OnClick(R.id.tv_hot_prompt)
    void OnHotPrompt() {
        //跳转到热门职位
         Intent intent=new Intent(getActivity(), HotPromptActivity.class);
         startActivity(intent);
    }

    @OnClick(R.id.tv_hot_positions)
    void OnHotPositions() {
        startActivity(new Intent(getActivity(), HotJobActivity.class));
    }

    @OnClick(R.id.tv_search_position)
    void onSearchPosition(){
        startActivity(new Intent(getActivity(), JobSearchActivity.class));
    }
}
